分享

谁可以详细介绍下Hbase profbuf 吗

Wyy_Ck 发表于 2017-1-16 10:31:23 [显示全部楼层] 回帖奖励 阅读模式 关闭右栏 9 7273
谁可以详细介绍下Hbase  profbuf 吗?  怎么使用的?


谢 谢

已有(9)人评论

跳转到指定楼层
yuwenge 发表于 2017-1-16 10:40:05
这里有专门的文章介绍,希望有所帮助
深入分析HBase-RPC(Protobuf)实现机制
http://www.aboutyun.com/thread-9364-1-1.html


回复

使用道具 举报

Wyy_Ck 发表于 2017-1-16 14:47:30
yuwenge 发表于 2017-1-16 10:40
这里有专门的文章介绍,希望有所帮助
深入分析HBase-RPC(Protobuf)实现机制
http://www.aboutyun.com/thr ...

仔细看了下您的分享。不过还有一个不知道。可以说下protobuf在大数据的应用场景吗 ?  目前项目经验较少,所以还请帮忙指导下



O(∩_∩)O谢谢
回复

使用道具 举报

Wyy_Ck 发表于 2017-1-16 14:55:01
protobuf生成生成一堆方法,谁知道这些方法都是什么作用呢
回复

使用道具 举报

Wyy_Ck 发表于 2017-1-16 14:55:54
protobuf编译后,生成java代码,生成一堆方法,谁知道这些方法都是什么作用呢
回复

使用道具 举报

langke93 发表于 2017-1-16 15:30:34
Wyy_Ck 发表于 2017-1-16 14:55
protobuf编译后,生成java代码,生成一堆方法,谁知道这些方法都是什么作用呢

这个其实还是对面向对象的理解不够。不过楼主还是很好学的。
面向对象的编程有类和方法,变量等,方法完成想实现的功能。当然如果楼主哪个具体方法不明白可列出来。大家一起看看
回复

使用道具 举报

tntzbzc 发表于 2017-1-16 16:25:16
这有关于protobuf的开发文档,楼主可以研究下
ProtoBuf开发者指南.rar (209.84 KB, 下载次数: 3)
回复

使用道具 举报

Wyy_Ck 发表于 2017-1-16 16:25:17
langke93 发表于 2017-1-16 15:30
这个其实还是对面向对象的理解不够。不过楼主还是很好学的。
面向对象的编程有类和方法,变量等,方法完 ...

见笑了,我先简单列举下这里面几个方法我简单理解理解:
1、newBuilder()   new出一个实例对象
2、        Person person = builder.build();
        byte[] buf = person.toByteArray();
将对象序列化为字节。    ----------为了方便传输吗? 方便了什么呢?
3、Person person2 = PersonProbuf.Person.parseFrom(buf);  -----------反序列化,得到对象实例。

问题1: 这个在大数据什么场景下使用,有什么好处呢?  因为没有做过项目,所以很是盲目。
问题2: 这么盲目,有没有什么改善学习效率的方法呢? 自己搭建了一个分布式的集群环境,部署了hadoop Hbase等基本组件。

person1.proto:
[mw_shl_code=applescript,true]message PersonTestId {     
    // ID(必需)  
    required int32 id = 1;  
}  
[/mw_shl_code]

protoc  --java_out=./src   ./proto/person1.proto生成的java代码:

[mw_shl_code=java,true]// Generated by the protocol buffer compiler.  DO NOT EDIT!
// source: proto/person1.proto

public final class Person1 {
  private Person1() {}
  public static void registerAllExtensions(
      com.google.protobuf.ExtensionRegistry registry) {
  }
  public interface PersonTestIdOrBuilder
      extends com.google.protobuf.MessageOrBuilder {

    // required int32 id = 1;
    /**
     * <code>required int32 id = 1;</code>
     *
     * <pre>
     * ID(必需)  
     * </pre>
     */
    boolean hasId();
    /**
     * <code>required int32 id = 1;</code>
     *
     * <pre>
     * ID(必需)  
     * </pre>
     */
    int getId();
  }
  /**
   * Protobuf type {@code PersonTestId}
   */
  public static final class PersonTestId extends
      com.google.protobuf.GeneratedMessage
      implements PersonTestIdOrBuilder {
    // Use PersonTestId.newBuilder() to construct.
    private PersonTestId(com.google.protobuf.GeneratedMessage.Builder<?> builder) {
      super(builder);
      this.unknownFields = builder.getUnknownFields();
    }
    private PersonTestId(boolean noInit) { this.unknownFields = com.google.protobuf.UnknownFieldSet.getDefaultInstance(); }

    private static final PersonTestId defaultInstance;
    public static PersonTestId getDefaultInstance() {
      return defaultInstance;
    }

    public PersonTestId getDefaultInstanceForType() {
      return defaultInstance;
    }

    private final com.google.protobuf.UnknownFieldSet unknownFields;
    @java.lang.Override
    public final com.google.protobuf.UnknownFieldSet
        getUnknownFields() {
      return this.unknownFields;
    }
    private PersonTestId(
        com.google.protobuf.CodedInputStream input,
        com.google.protobuf.ExtensionRegistryLite extensionRegistry)
        throws com.google.protobuf.InvalidProtocolBufferException {
      initFields();
      int mutable_bitField0_ = 0;
      com.google.protobuf.UnknownFieldSet.Builder unknownFields =
          com.google.protobuf.UnknownFieldSet.newBuilder();
      try {
        boolean done = false;
        while (!done) {
          int tag = input.readTag();
          switch (tag) {
            case 0:
              done = true;
              break;
            default: {
              if (!parseUnknownField(input, unknownFields,
                                     extensionRegistry, tag)) {
                done = true;
              }
              break;
            }
            case 8: {
              bitField0_ |= 0x00000001;
              id_ = input.readInt32();
              break;
            }
          }
        }
      } catch (com.google.protobuf.InvalidProtocolBufferException e) {
        throw e.setUnfinishedMessage(this);
      } catch (java.io.IOException e) {
        throw new com.google.protobuf.InvalidProtocolBufferException(
            e.getMessage()).setUnfinishedMessage(this);
      } finally {
        this.unknownFields = unknownFields.build();
        makeExtensionsImmutable();
      }
    }
    public static final com.google.protobuf.Descriptors.Descriptor
        getDescriptor() {
      return Person1.internal_static_PersonTestId_descriptor;
    }

    protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
        internalGetFieldAccessorTable() {
      return Person1.internal_static_PersonTestId_fieldAccessorTable
          .ensureFieldAccessorsInitialized(
              Person1.PersonTestId.class, Person1.PersonTestId.Builder.class);
    }

    public static com.google.protobuf.Parser<PersonTestId> PARSER =
        new com.google.protobuf.AbstractParser<PersonTestId>() {
      public PersonTestId parsePartialFrom(
          com.google.protobuf.CodedInputStream input,
          com.google.protobuf.ExtensionRegistryLite extensionRegistry)
          throws com.google.protobuf.InvalidProtocolBufferException {
        return new PersonTestId(input, extensionRegistry);
      }
    };

    @java.lang.Override
    public com.google.protobuf.Parser<PersonTestId> getParserForType() {
      return PARSER;
    }

    private int bitField0_;
    // required int32 id = 1;
    public static final int ID_FIELD_NUMBER = 1;
    private int id_;
    /**
     * <code>required int32 id = 1;</code>
     *
     * <pre>
     * ID(必需)  
     * </pre>
     */
    public boolean hasId() {
      return ((bitField0_ & 0x00000001) == 0x00000001);
    }
    /**
     * <code>required int32 id = 1;</code>
     *
     * <pre>
     * ID(必需)  
     * </pre>
     */
    public int getId() {
      return id_;
    }

    private void initFields() {
      id_ = 0;
    }
    private byte memoizedIsInitialized = -1;
    public final boolean isInitialized() {
      byte isInitialized = memoizedIsInitialized;
      if (isInitialized != -1) return isInitialized == 1;

      if (!hasId()) {
        memoizedIsInitialized = 0;
        return false;
      }
      memoizedIsInitialized = 1;
      return true;
    }

    public void writeTo(com.google.protobuf.CodedOutputStream output)
                        throws java.io.IOException {
      getSerializedSize();
      if (((bitField0_ & 0x00000001) == 0x00000001)) {
        output.writeInt32(1, id_);
      }
      getUnknownFields().writeTo(output);
    }

    private int memoizedSerializedSize = -1;
    public int getSerializedSize() {
      int size = memoizedSerializedSize;
      if (size != -1) return size;

      size = 0;
      if (((bitField0_ & 0x00000001) == 0x00000001)) {
        size += com.google.protobuf.CodedOutputStream
          .computeInt32Size(1, id_);
      }
      size += getUnknownFields().getSerializedSize();
      memoizedSerializedSize = size;
      return size;
    }

    private static final long serialVersionUID = 0L;
    @java.lang.Override
    protected java.lang.Object writeReplace()
        throws java.io.ObjectStreamException {
      return super.writeReplace();
    }

    public static Person1.PersonTestId parseFrom(
        com.google.protobuf.ByteString data)
        throws com.google.protobuf.InvalidProtocolBufferException {
      return PARSER.parseFrom(data);
    }
    public static Person1.PersonTestId parseFrom(
        com.google.protobuf.ByteString data,
        com.google.protobuf.ExtensionRegistryLite extensionRegistry)
        throws com.google.protobuf.InvalidProtocolBufferException {
      return PARSER.parseFrom(data, extensionRegistry);
    }
    public static Person1.PersonTestId parseFrom(byte[] data)
        throws com.google.protobuf.InvalidProtocolBufferException {
      return PARSER.parseFrom(data);
    }
    public static Person1.PersonTestId parseFrom(
        byte[] data,
        com.google.protobuf.ExtensionRegistryLite extensionRegistry)
        throws com.google.protobuf.InvalidProtocolBufferException {
      return PARSER.parseFrom(data, extensionRegistry);
    }
    public static Person1.PersonTestId parseFrom(java.io.InputStream input)
        throws java.io.IOException {
      return PARSER.parseFrom(input);
    }
    public static Person1.PersonTestId parseFrom(
        java.io.InputStream input,
        com.google.protobuf.ExtensionRegistryLite extensionRegistry)
        throws java.io.IOException {
      return PARSER.parseFrom(input, extensionRegistry);
    }
    public static Person1.PersonTestId parseDelimitedFrom(java.io.InputStream input)
        throws java.io.IOException {
      return PARSER.parseDelimitedFrom(input);
    }
    public static Person1.PersonTestId parseDelimitedFrom(
        java.io.InputStream input,
        com.google.protobuf.ExtensionRegistryLite extensionRegistry)
        throws java.io.IOException {
      return PARSER.parseDelimitedFrom(input, extensionRegistry);
    }
    public static Person1.PersonTestId parseFrom(
        com.google.protobuf.CodedInputStream input)
        throws java.io.IOException {
      return PARSER.parseFrom(input);
    }
    public static Person1.PersonTestId parseFrom(
        com.google.protobuf.CodedInputStream input,
        com.google.protobuf.ExtensionRegistryLite extensionRegistry)
        throws java.io.IOException {
      return PARSER.parseFrom(input, extensionRegistry);
    }

    public static Builder newBuilder() { return Builder.create(); }
    public Builder newBuilderForType() { return newBuilder(); }
    public static Builder newBuilder(Person1.PersonTestId prototype) {
      return newBuilder().mergeFrom(prototype);
    }
    public Builder toBuilder() { return newBuilder(this); }

    @java.lang.Override
    protected Builder newBuilderForType(
        com.google.protobuf.GeneratedMessage.BuilderParent parent) {
      Builder builder = new Builder(parent);
      return builder;
    }
    /**
     * Protobuf type {@code PersonTestId}
     */
    public static final class Builder extends
        com.google.protobuf.GeneratedMessage.Builder<Builder>
       implements Person1.PersonTestIdOrBuilder {
      public static final com.google.protobuf.Descriptors.Descriptor
          getDescriptor() {
        return Person1.internal_static_PersonTestId_descriptor;
      }

      protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
          internalGetFieldAccessorTable() {
        return Person1.internal_static_PersonTestId_fieldAccessorTable
            .ensureFieldAccessorsInitialized(
                Person1.PersonTestId.class, Person1.PersonTestId.Builder.class);
      }

      // Construct using Person1.PersonTestId.newBuilder()
      private Builder() {
        maybeForceBuilderInitialization();
      }

      private Builder(
          com.google.protobuf.GeneratedMessage.BuilderParent parent) {
        super(parent);
        maybeForceBuilderInitialization();
      }
      private void maybeForceBuilderInitialization() {
        if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) {
        }
      }
      private static Builder create() {
        return new Builder();
      }

      public Builder clear() {
        super.clear();
        id_ = 0;
        bitField0_ = (bitField0_ & ~0x00000001);
        return this;
      }

      public Builder clone() {
        return create().mergeFrom(buildPartial());
      }

      public com.google.protobuf.Descriptors.Descriptor
          getDescriptorForType() {
        return Person1.internal_static_PersonTestId_descriptor;
      }

      public Person1.PersonTestId getDefaultInstanceForType() {
        return Person1.PersonTestId.getDefaultInstance();
      }

      public Person1.PersonTestId build() {
        Person1.PersonTestId result = buildPartial();
        if (!result.isInitialized()) {
          throw newUninitializedMessageException(result);
        }
        return result;
      }

      public Person1.PersonTestId buildPartial() {
        Person1.PersonTestId result = new Person1.PersonTestId(this);
        int from_bitField0_ = bitField0_;
        int to_bitField0_ = 0;
        if (((from_bitField0_ & 0x00000001) == 0x00000001)) {
          to_bitField0_ |= 0x00000001;
        }
        result.id_ = id_;
        result.bitField0_ = to_bitField0_;
        onBuilt();
        return result;
      }

      public Builder mergeFrom(com.google.protobuf.Message other) {
        if (other instanceof Person1.PersonTestId) {
          return mergeFrom((Person1.PersonTestId)other);
        } else {
          super.mergeFrom(other);
          return this;
        }
      }

      public Builder mergeFrom(Person1.PersonTestId other) {
        if (other == Person1.PersonTestId.getDefaultInstance()) return this;
        if (other.hasId()) {
          setId(other.getId());
        }
        this.mergeUnknownFields(other.getUnknownFields());
        return this;
      }

      public final boolean isInitialized() {
        if (!hasId()) {
         
          return false;
        }
        return true;
      }

      public Builder mergeFrom(
          com.google.protobuf.CodedInputStream input,
          com.google.protobuf.ExtensionRegistryLite extensionRegistry)
          throws java.io.IOException {
        Person1.PersonTestId parsedMessage = null;
        try {
          parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
        } catch (com.google.protobuf.InvalidProtocolBufferException e) {
          parsedMessage = (Person1.PersonTestId) e.getUnfinishedMessage();
          throw e;
        } finally {
          if (parsedMessage != null) {
            mergeFrom(parsedMessage);
          }
        }
        return this;
      }
      private int bitField0_;

      // required int32 id = 1;
      private int id_ ;
      /**
       * <code>required int32 id = 1;</code>
       *
       * <pre>
       * ID(必需)  
       * </pre>
       */
      public boolean hasId() {
        return ((bitField0_ & 0x00000001) == 0x00000001);
      }
      /**
       * <code>required int32 id = 1;</code>
       *
       * <pre>
       * ID(必需)  
       * </pre>
       */
      public int getId() {
        return id_;
      }
      /**
       * <code>required int32 id = 1;</code>
       *
       * <pre>
       * ID(必需)  
       * </pre>
       */
      public Builder setId(int value) {
        bitField0_ |= 0x00000001;
        id_ = value;
        onChanged();
        return this;
      }
      /**
       * <code>required int32 id = 1;</code>
       *
       * <pre>
       * ID(必需)  
       * </pre>
       */
      public Builder clearId() {
        bitField0_ = (bitField0_ & ~0x00000001);
        id_ = 0;
        onChanged();
        return this;
      }

      // @@protoc_insertion_point(builder_scope:PersonTestId)
    }

    static {
      defaultInstance = new PersonTestId(true);
      defaultInstance.initFields();
    }

    // @@protoc_insertion_point(class_scope:PersonTestId)
  }

  private static com.google.protobuf.Descriptors.Descriptor
    internal_static_PersonTestId_descriptor;
  private static
    com.google.protobuf.GeneratedMessage.FieldAccessorTable
      internal_static_PersonTestId_fieldAccessorTable;

  public static com.google.protobuf.Descriptors.FileDescriptor
      getDescriptor() {
    return descriptor;
  }
  private static com.google.protobuf.Descriptors.FileDescriptor
      descriptor;
  static {
    java.lang.String[] descriptorData = {
      "\n\023proto/person1.proto\"\032\n\014PersonTestId\022\n\n" +
      "\002id\030\001 \002(\005"
    };
    com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner =
      new com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner() {
        public com.google.protobuf.ExtensionRegistry assignDescriptors(
            com.google.protobuf.Descriptors.FileDescriptor root) {
          descriptor = root;
          internal_static_PersonTestId_descriptor =
            getDescriptor().getMessageTypes().get(0);
          internal_static_PersonTestId_fieldAccessorTable = new
            com.google.protobuf.GeneratedMessage.FieldAccessorTable(
              internal_static_PersonTestId_descriptor,
              new java.lang.String[] { "Id", });
          return null;
        }
      };
    com.google.protobuf.Descriptors.FileDescriptor
      .internalBuildGeneratedFileFrom(descriptorData,
        new com.google.protobuf.Descriptors.FileDescriptor[] {
        }, assigner);
  }

  // @@protoc_insertion_point(outer_class_scope)
}
[/mw_shl_code]
回复

使用道具 举报

Wyy_Ck 发表于 2017-1-16 16:28:43
tntzbzc 发表于 2017-1-16 16:25
这有关于protobuf的开发文档,楼主可以研究下

好的。O(∩_∩)O谢谢
回复

使用道具 举报

langke93 发表于 2017-1-16 16:56:00
Wyy_Ck 发表于 2017-1-16 16:25
见笑了,我先简单列举下这里面几个方法我简单理解理解:
1、newBuilder()   new出一个实例对象
2、        Per ...

1、newBuilder()   new出一个实例对象
对的,赞同楼主的观点。(protobuf是不可以自己new对象,如果要设置属性值,需用newBuilder()生成Builder对象,然后build生成需要原对象数据)
2、        Person person = builder.build();
        byte[] buf = person.toByteArray();
将对象序列化为字节。    ----------为了方便传输吗? 方便了什么呢?
这个跟序列化就有关系了,方便传输是它的一大特点,特别是在分布式框架中,hadoop,spark都是用的rpc。
3、Person person2 = PersonProbuf.Person.parseFrom(buf);  -----------反序列化,得到对象实例。
有序列化,所以有反序列化,这两个是对应的
问题1: 这个在大数据什么场景下使用,有什么好处呢?  因为没有做过项目,所以很是盲目。
由于大数据都是分布式框架,所以protobuf是比较好的一个框架,调用方便
问题2: 这么盲目,有没有什么改善学习效率的方法呢? 自己搭建了一个分布式的集群环境,部署了hadoop Hbase等基本组件。
学习是有一个过程的,别着急。

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

推荐上一条 /2 下一条