diff options
author | Josh Haberman <haberman@google.com> | 2013-02-15 16:27:18 -0800 |
---|---|---|
committer | Josh Haberman <haberman@google.com> | 2013-02-15 16:27:18 -0800 |
commit | 7d3e2bd2c4cfd1296d1d6f996d7548de26540d41 (patch) | |
tree | b4b35967b3322c65cfb1a32220e8718de09d85fc /upb/google/cord.h | |
parent | ea198bdcf947ba4bd51474bdd4f7b82b5e4cf41d (diff) |
Sync with 8 months of Google-internal development.
Many things have changed and been simplified.
The memory-management story for upb_def and upb_handlers
is much more robust; upb_def and upb_handlers should be
fairly stable interfaces now. There is still much work
to do for the runtime component (upb_sink).
Diffstat (limited to 'upb/google/cord.h')
-rw-r--r-- | upb/google/cord.h | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/upb/google/cord.h b/upb/google/cord.h new file mode 100644 index 0000000..c579c0c --- /dev/null +++ b/upb/google/cord.h @@ -0,0 +1,48 @@ +// +// upb - a minimalist implementation of protocol buffers. +// +// Copyright (c) 2011-2012 Google Inc. See LICENSE for details. +// Author: Josh Haberman <jhaberman@gmail.com> +// +// Functionality for interoperating with Cord. Only needed inside Google. + +#ifndef UPB_GOOGLE_CORD_H +#define UPB_GOOGLE_CORD_H + +#include "strings/cord.h" +#include "upb/bytestream.h" + +namespace upb { + +namespace proto2_bridge_google3 { class FieldAccessor; } +namespace proto2_bridge_opensource { class FieldAccessor; } + +namespace google { + +class P2R_Handlers; + +class CordSupport { + private: + UPB_DISALLOW_POD_OPS(CordSupport); + + inline static void AssignToCord(const upb::ByteRegion* r, Cord* cord) { + // TODO(haberman): ref source data if source is a cord. + cord->Clear(); + uint64_t ofs = r->start_ofs(); + while (ofs < r->end_ofs()) { + size_t len; + const char *buf = r->GetPtr(ofs, &len); + cord->Append(StringPiece(buf, len)); + ofs += len; + } + } + + friend class ::upb::proto2_bridge_google3::FieldAccessor; + friend class ::upb::proto2_bridge_opensource::FieldAccessor; + friend class P2R_Handlers; +}; + +} // namespace google +} // namespace upb + +#endif // UPB_GOOGLE_CORD_H |