You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by st...@apache.org on 2011/04/16 14:54:52 UTC

svn commit: r1093982 - in /subversion/trunk/subversion: include/private/svn_temp_serializer.h libsvn_subr/svn_temp_serializer.c

Author: stefan2
Date: Sat Apr 16 12:54:51 2011
New Revision: 1093982

URL: http://svn.apache.org/viewvc?rev=1093982&view=rev
Log:
Add a new serialization startup function that allows for
modifying already serialized data.

* subversion/include/private/svn_temp_serializer.h
  (svn_temp_serializer__init_append): declare new function
* subversion/libsvn_subr/svn_temp_serializer.c
  (svn_temp_serializer__init_append): implement it

Modified:
    subversion/trunk/subversion/include/private/svn_temp_serializer.h
    subversion/trunk/subversion/libsvn_subr/svn_temp_serializer.c

Modified: subversion/trunk/subversion/include/private/svn_temp_serializer.h
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/include/private/svn_temp_serializer.h?rev=1093982&r1=1093981&r2=1093982&view=diff
==============================================================================
--- subversion/trunk/subversion/include/private/svn_temp_serializer.h (original)
+++ subversion/trunk/subversion/include/private/svn_temp_serializer.h Sat Apr 16 12:54:51 2011
@@ -70,6 +70,33 @@ svn_temp_serializer__init(const void *so
                           apr_pool_t *pool);
 
 /**
+ * Continue the serialization process of the @a source_struct that has
+ * already been serialized to @a buffer but contains references to new
+ * objects yet to serialize. I.e. this function allows you to append
+ * data to serialized structures returned by @ref svn_temp_serializer__get.
+ *
+ * The current size of the serialized data is given in @a currently_used.
+ * If the allocated data buffer is actually larger, you may specifiy that
+ * size in @a currently_allocated to prevent unnecessary re-allocations.
+ * Otherwise, set it to 0.
+ *
+ * All allocations will be made from @a pool.
+ *
+ * Please note that only sub-structures of @a source_struct may be added.
+ * To add item referenced from other parts of the buffer, serialize from
+ * @a source_struct first, get the result from @ref svn_temp_serializer__get
+ * and call svn_temp_serializer__init_append for the next part.
+ *
+ * @return the serization context.
+ */
+svn_temp_serializer__context_t *
+svn_temp_serializer__init_append(const void *buffer,
+                                 const void *source_struct,
+                                 apr_size_t currently_used,
+                                 apr_size_t currently_allocated,
+                                 apr_pool_t *pool);
+
+/**
  * Begin serialization of a referenced sub-structure within the
  * serialization @a context. @a source_struct must be a reference to the
  * pointer in the original parent structure so that the correspondence in

Modified: subversion/trunk/subversion/libsvn_subr/svn_temp_serializer.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/svn_temp_serializer.c?rev=1093982&r1=1093981&r2=1093982&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/svn_temp_serializer.c (original)
+++ subversion/trunk/subversion/libsvn_subr/svn_temp_serializer.c Sat Apr 16 12:54:51 2011
@@ -133,6 +133,45 @@ svn_temp_serializer__init(const void *so
   return context;
 }
 
+/* Continue the serialization process of the SOURCE_STRUCT that has already
+ * been serialized to BUFFER but contains references to new objects yet to
+ * serialize. The current size of the serialized data is given in
+ * CURRENTLY_USED. If the allocated data buffer is actually larger, you may
+ * specifiy that in CURRENTLY_ALLOCATED to prevent unnecessary allocations.
+ * Otherwise, set it to 0. All allocations will be made from POOl.
+ */
+svn_temp_serializer__context_t *
+svn_temp_serializer__init_append(const void *buffer,
+                                 const void *source_struct,
+                                 apr_size_t currently_used,
+                                 apr_size_t currently_allocated,
+                                 apr_pool_t *pool)
+{
+  /* determine the current memory buffer capacity */
+  apr_size_t init_size = currently_allocated < currently_used
+                       ? currently_used
+                       : currently_allocated;
+
+  /* create the serialization context and initialize it */
+  svn_temp_serializer__context_t *context = apr_palloc(pool, sizeof(*context));
+  context->pool = pool;
+
+  /* use BUFFER as serialization target */
+  context->buffer = svn_stringbuf_create_ensure(0, pool);
+  context->buffer->data = buffer;
+  context->buffer->len = currently_used;
+  context->buffer->blocksize = init_size;
+
+  /* SOURCE_STRUCT is our serialization root */
+  context->source = apr_palloc(pool, sizeof(*context->source));
+  context->source->source_struct = source_struct;
+  context->source->target_offset = source_struct - buffer;
+  context->source->upper = NULL;
+
+  /* done */
+  return context;
+}
+
 /* Utility function replacing the serialized pointer corresponding to
  * *SOURCE_POINTER with the offset that it will be put when being append
  * right after this function call.