<commit_before>// Copyright (c) 2014, Dropbox INC. All rights reserved.
// www.dropbox.com
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
//     * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//     * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// `AS IS` AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

/*
TODO(andrei): write how to use it

*/

package generator

import (
    "strings"

    "github.com/dropbox/goprotoc/gogoproto"
    descriptor "github.com/dropbox/goprotoc/protoc-gen-dgo/descriptor"
)

const expResizeThreshold string = "1000000"

type fieldNames struct {
    typeName      string
    fieldName     string
    fieldType     string
    fieldTypeBase string
    field         *descriptor.FieldDescriptorProto
    message       *Descriptor
    protoType     descriptor.FieldDescriptorProto_Type
}
<commit_msg>Add readme for api code<commit_after>// Copyright (c) 2014, Dropbox INC. All rights reserved.
// www.dropbox.com
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
//     * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//     * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// `AS IS` AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

/*
The api function generates accessor methods in respect with the c++ api
documentation: https://developers.google.com/protocol-buffers/docs/reference/cpp-generated

The generation of api tests are enabled using one of the following extensions:

  - testgen
  - testgen_all

Given the following message:

message TestSingular {
    optional TestMessage msgs = 1;
    optional double vald = 2;
    optional float valf = 3;
}

the api code will generate the following code:

func (m *TestSingular) MutateMsgs() (field *TestMessage, err error) {
    if m == nil {
        return nil, errors.New("Cannot mutate a nil message")
    }
    if !m.xxx_IsMsgsSet {
        m.xxx_IsMsgsSet = true
        m.msgs = new(TestMessage)
    }
    return m.msgs, nil
}

func (m *TestSingular) HasMsgs() (isSet bool) {
    if m != nil && m.xxx_IsMsgsSet {
        return true
    }
    return false
}

func (m *TestSingular) ClearMsgs() {
    if m != nil {
        m.msgs.Clear()
        m.xxx_IsMsgsSet = false

    }
}

func (m *TestSingular) SetVald(value float64) (err error) {
    if m == nil {
        return errors.New("Cannot assign to nil message")
    }
    m.xxx_IsValdSet = true
    m.vald = value
    return nil
}

func (m *TestSingular) HasVald() (isSet bool) {
    if m != nil && m.xxx_IsValdSet {
        return true
    }
    return false
}

func (m *TestSingular) ClearVald() {
    if m != nil {
        m.xxx_IsValdSet = false
    }
}

func (m *TestSingular) SetValf(value float32) (err error) {
    if m == nil {
        return errors.New("Cannot assign to nil message")
    }
    m.xxx_IsValfSet = true
    m.valf = value
    return nil
}

func (m *TestSingular) HasValf() (isSet bool) {
    if m != nil && m.xxx_IsValfSet {
        return true
    }
    return false
}

func (m *TestSingular) ClearValf() {
    if m != nil {
        m.xxx_IsValfSet = false
    }
}

func (m *TestSingular) Clear() {
    if m != nil {
        m.msgs.Clear()
        m.xxx_IsMsgsSet = false

        m.ClearVald()
        m.ClearValf()
    }
}
*/

package generator

import (
    "strings"

    "dropbox/gogoprotobuf/gogoproto"
    descriptor "dropbox/gogoprotobuf/protoc-gen-dgo/descriptor"
)

const expResizeThreshold string = "1000000"

type fieldNames struct {
    typeName      string
    fieldName     string
    fieldType     string
    fieldTypeBase string
    field         *descriptor.FieldDescriptorProto
    message       *Descriptor
    protoType     descriptor.FieldDescriptorProto_Type
}

{'fraction_non_alphanumeric': 0.08111816155033442, 'fraction_numerical': 0.004973417938604013, 'mean_word_length': 3.0528144544822795, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 1, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7035442', 'n_tokens_mistral': 1754, 'n_tokens_neox': 1623, 'n_words': 660}